# coding=utf-8

import pandas as pd


def csv2excel(full_path_csv):
    try:
        df = pd.read_csv(full_path_csv)
        ew = pd.ExcelWriter(str(full_path_csv).replace('.csv', '.xlsx'))
        df.to_excel(ew, header=True, index=False)
        ew.save()
    except Exception as e:
        print(e)


def sort_csv(full_path_csv, sort_k='ndays'):
    try:
        df = pd.read_csv(full_path_csv)
        if sort_k:
            df = df.sort_values(sort_k, ascending=False)
        df.to_csv(full_path_csv, header=True, index=False)
        print(full_path_csv)
    except Exception as e:
        print(e)


def read_csv(full_path_csv, filter_ndays=15, select_k='ndays'):
    df = pd.read_csv(full_path_csv)
    return set([f'{d[1]} {d[0]}' for d in df[df[select_k] > filter_ndays].values.tolist()])


if __name__ == '__main__':
    csv2excel(r'support.csv')